package net.m2technologies.open_arm.transaction;

import net.m2technologies.open_arm.ArmErrorHandler;
import net.m2technologies.open_arm.utilities.generic_object_functions.GenericObjectFunctions;
import org.opengroup.arm40.transaction.ArmInterface;
import org.opengroup.arm40.transaction.ArmTransactionFactory;

/**
 * Copyright 2005 Mark Masterson<br> <br> Licensed under the Apache License, Version 2.0 (the "License");<br> you may
 * not use this file except in compliance with the License.<br> You may obtain a copy of the License at<br> <br>
 * http://www.apache.org/licenses/LICENSE-2.0<br> <br> Unless required by applicable law or agreed to in writing,
 * software<br> distributed under the License is distributed on an "AS IS" BASIS,<br> WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied.<br> See the License for the specific language governing permissions and<br>
 * limitations under the License.<br>
 * <p/>
 * <p>Description: </p>
 *
 * @author Mark Masterson
 * @version 0.010
 */
public abstract class ArmInterfaceImpl implements ArmInterface {

    private final ArmTransactionFactory creatingFactory;
    private int errorCode;
    protected static final int HASH_CODE_MAGIC_NUMBER = 29;

    protected ArmInterfaceImpl(final ArmTransactionFactory creatingFactory) {
        this.creatingFactory = creatingFactory;
        this.errorCode = 0;
    }

    public synchronized int getErrorCode() {
        return this.errorCode;
    }

    public synchronized int setErrorCode(final int errorCode) {
        this.errorCode = errorCode;
        if (0 < this.errorCode && null != this.creatingFactory) {
            ((ArmErrorHandler) this.creatingFactory).fireErrorEvent(this,
                                                                    new StringBuffer().append("[setErrorCode] ")
                                                                            .append(this.errorCode)
                                                                            .toString());
        }
        return this.errorCode;
    }

    public String getErrorMessage(final int errorCode) {
        return null;
    }

    public ArmTransactionFactory getCreatingFactory() {
        return creatingFactory;
    }

    public String toString() {
        return (new GenericObjectFunctions()).toString(this);
    }

}
